﻿--HEADER Added FundBookEntityId column
alter table [UDS].[TradeIdToTradeOriginalId]
ADD [FundBookEntityId] int null

DELETE FROM uds.TradeIdToTradeOriginalId
WHERE TradeId in
(
	select tt.TradeId from uds.TradeIdToTradeOriginalId tt
	left join uds.Trade t on t.Id=tt.TradeId
	where t.Id is null
)
GO

UPDATE T
SET 
	T.FundBookEntityId=TT.FundBookEntityId
FROM [UDS].[TradeIdToTradeOriginalId] T 
JOIN [UDS].[Trade] TT ON T.TradeId=TT.Id

ALTER TABLE [UDS].[TradeIdToTradeOriginalId]
ALTER COLUMN [FundBookEntityId] int NOT NULL







